package com.alibaba.shopping_order_service.listener;

import com.alibaba.shopping_common.pojo.Orders;
import com.alibaba.shopping_common.service.OrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName CheckOrdersListener
 * @Description 延迟队列的消费者
 * @Author Leo
 * @Date 2024/12/19 19:24
 */
@Service
@RocketMQMessageListener(topic ="check_orders_queue",consumerGroup = "check_orders_group")
public class CheckOrdersListener implements RocketMQListener<String> {
    @Autowired
    private OrderService orderService;

    @Override
    public void onMessage(String orderId) {
        // 消费消息
        Orders orders = orderService.findById(orderId);
        // 过滤出还处于未支付状态的订单
        if (orders.getStatus() == 1){
            System.out.println("10s内超时未支付，关闭订单");
            // 更新订单状态为关闭
            orders.setStatus(6);
            orderService.updateOrder(orders);
        }
    }
}




